
export default {
    namespaced: true,
    state: () => ({
        commentList: []
    }),
    mutations: {
        purgeCommentList(state) {
            state.commentList=[]
        },
        deleteCommentById(state, cid) {
            const index = state.commentList.findIndex(c => c.commentId == cid)
            console.log(index);
            if (index != -1) {
                return state.commentList.splice(index, 1);
            }
            const chasSubList = state.commentList.filter(v=>v.subComments.length > 0)
            for (let i = 0; i < chasSubList.length; i++) {
                const sub = chasSubList[i].subComments;
                const index = sub.findIndex(c => c.commentId == cid)
                return sub.splice(index, 1)
            }
        },
        initCommentList(state, commentList) {
            state.commentList = commentList
        },
        appendComments(state, commentList) {
            state.commentList.push(...commentList)
        }
    }
}